package com.ims.DAO;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.ims.hibernate.Student;
import com.ims.util.HibernateUtil;



public class StudentDAO {
	
	public void StudentDAO() {
	}
	private long studentId;
	private String firstName;
	private String lastName;
	private String profilepic;
	private String gender;
	private String dob;
	private String address;
	private long deptId;
	private String yearEnrolled;
	private float overallGPA;
	private String phoneNumber;
	private String emailAddress;
	
	
	
	/*public static void main(String[] args) {
		StudentDAO emp = new StudentDAO();
		
	Long a =	emp.saveStudent(2, "waseem", "abass", 1, "male", "1998:12/01", "example@gmail.com", (float) 2.5,  "45645645",  "abc.jpg","cvcvb", "house # 2" );
	}*/
	
	public long getStudentId() {
		return studentId;
	}

	public void setStudentId(long studentId) {
		this.studentId = studentId;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getProfilepic() {
		return profilepic;
	}

	public void setProfilepic(String profilepic) {
		this.profilepic = profilepic;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getDob() {
		return dob;
	}

	public void setDob(String dob) {
		this.dob = dob;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public long getDeptId() {
		return deptId;
	}

	public void setDeptId(long deptId) {
		this.deptId = deptId;
	}

	public String getYearEnrolled() {
		return yearEnrolled;
	}

	public void setYearEnrolled(String yearEnrolled) {
		this.yearEnrolled = yearEnrolled;
	}

	public float getOverallGPA() {
		return overallGPA;
	}

	public void setOverallGPA(float overallGPA) {
		this.overallGPA = overallGPA;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public Long saveStudent()
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		Long p = null;
		
		try {
			transaction = session.beginTransaction();
			Student student = new Student();
			student.setStudentId(studentId);
			student.setFirstName(firstName);
			student.setLastName(lastName);
			
			student.setGender(gender);
			student.setDob(dob);
			student.setEmailAddress(emailAddress);
			student.setOverallGPA(overallGPA);
			student.setPhoneNumber(phoneNumber);
			student.setProfilepic(profilepic);
			student.setYearEnrolled(yearEnrolled);
			student.setDeptId(deptId);
			student.setAddress(address);
			System.out.println(studentId);
			session.save(student);
			transaction.commit();
		} catch (HibernateException e) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		return p;
	}
	
}
